package com.elsa.smart_buffet.service.impl;

import com.elsa.smart_buffet.mapper.DayMapper;
import com.elsa.smart_buffet.mapper.MonthMapper;
import com.elsa.smart_buffet.mapper.SaleEchartsMapper;
import com.elsa.smart_buffet.pojo.Day;
import com.elsa.smart_buffet.pojo.Month;
import com.elsa.smart_buffet.pojo.ResultBox.CallBackMessage;
import com.elsa.smart_buffet.pojo.ResultBox.ResponseResult;
import com.elsa.smart_buffet.pojo.vo.SaleEchartsStats;
import com.elsa.smart_buffet.service.SaleEchartsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName : SaleEchartsServiceImpl  //类名
 * @Author : elsa //作者
 */
@Service
@Transactional
@Slf4j
public class SaleEchartsServiceImpl implements SaleEchartsService {

    @Autowired
    private SaleEchartsMapper saleEchartsMapper;

    @Autowired
    private DayMapper dayMapper;

    @Autowired
    private MonthMapper monthMapper;

    @Override
    public ResponseResult getSaleEchartsByDate(String date) {
        date = date.replace("-", "");
        SaleEchartsStats saleEchartsStats = new SaleEchartsStats();
        try {
            Day day = dayMapper.selectById(date);
            if(day == null) {
                saleEchartsStats.setExpend(0);
                saleEchartsStats.setIncome(0);
            } else {
                saleEchartsStats = saleEchartsMapper.getSaleEchartsStatsByDate(date);
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }
        return new ResponseResult(CallBackMessage.SUCCESS, saleEchartsStats);
    }

    @Override
    public ResponseResult getSaleEchartsStatsByMonth(String month) {
        month = month.replace("-", "");
        SaleEchartsStats saleEchartsStats = new SaleEchartsStats();
        try {
            Month month1 = monthMapper.selectById(month);
            if(month1 == null) {
                saleEchartsStats.setExpend(0);
                saleEchartsStats.setIncome(0);
            } else {
                saleEchartsStats = saleEchartsMapper.getSaleEchartsStatsByMonth(month);
            }
        } catch (Exception e) {
            log.info(e.getMessage());
        }
        return new ResponseResult(CallBackMessage.SUCCESS, saleEchartsStats);
    }


}
